/**
 * 组件代码
 */
Vue.component('comSougnA', {
    name: 'comSougnA',
    props: ['config', 'data'],
    data: function () {
        return {
            content: "",
            href: ""
        }
    },
    computed: {
        myConfig: function () {
            var data = {};
            for (var item of this.config) {
                data[item.id] = item.value;
            }
            var defaultV = {
                fontSize: data.fontSize + 'px',
                color: data.color,
                lineHeight: data.lineHeight + 'px',
                href: data.href,
                content: data.content,
                textDecoration: data.haveLine
            };
            this.href = data.href;
            var data = window.getValue(data.content);
            if (typeof (data[0]) == 'string') {
                this.content = data[0];
            } else if (data[0] != undefined && data[0][0] != undefined) {
                this.content = data[0][0];
            } else {
                this.content = "";
            }
            return defaultV;
        },
    },
    watch: {
        data: function (oldValue, newValue) {
            this.dataChange();
        }
    },
    mounted() {
        this.dataChange();
    },
    methods: {
        dataChange: function () {
            this.href = this.myConfig.href;
            var data = window.getValue(this.myConfig.content);
            if (typeof (data[0]) == 'string') {
                this.content = data[0];
            } else if (data[0] != undefined && data[0][0] != undefined) {
                this.content = data[0][0];
            } else {
                this.content = "";
            }
        },
        toHref: function () {
            if (this.myConfig.openType == "now") {
                window.location.href = this.href;
            } else {
                window.open("", this.href);
            }
        }
    },
    template: `<div :style="myConfig" @click="toHref">{{content}}</div>`,
});
/**
 * 配置项
 * @type {{name: string, id: string, type: string, value: string}[]}
 */
var comSougnAConfig = [{
    name: "字体颜色",
    type: "color",
    value: "#eee",
    id: "color"
}, {
    name: "是否有下划线",
    type: "select",
    config: [
        {
            value: 'underline',
            label: '定义文本下的一条线'
        }, {
            value: 'overline',
            label: '定义文本上的一条线'
        }, {
            value: 'line-through',
            label: '定义穿过文本下的一条线'
        }, {
            value: 'blink',
            label: '定义闪烁的文本'
        }],
    value: "",
    id: "haveLine"
}, {
    name: "打开方式",
    type: "select",
    config: [
        {
            value: 'new',
            label: '新的页面'
        }, {
            value: 'now',
            label: '当前页面'
        }],
    value: "",
    id: "openType"
}, {
    name: "跳转连接",
    type: "text",
    value: "",
    id: "href"
}, {
    name: "内容",
    type: "data",
    value: "",
    id: "content"
}, {
    name: "字体大小",
    type: "size",
    value: 20,
    id: "fontSize"
}, {
    name: "行高",
    type: "size",
    value: 20,
    id: "lineHeight"
}]
